package tech.aistar.mapper;

import org.apache.ibatis.annotations.*;
import tech.aistar.dto.AgentGrade;
import tech.aistar.entity.Agent;

import java.util.List;


public interface AgentMapper {

    @Select("select * from agent")
    List<Agent> selectAll();

    @Select("select a.id,a.photo,a.name,a.gender,a.phone,e.grade,a.license from agent a join evaluate e on a.id=e.agent_id")
    List<AgentGrade> selectAgent();

    //@Select("select a.id,a.photo,a.name,a.gender,a.phone,e.grade,a.license from agent a join evaluate e on a.id=e.agent_id where a.name=#{name}")
    List<AgentGrade> selectAgentByName(String name);

    @Insert("insert into agent values(photo,license,identityCardNumber," +
            "registerId,namephotograph,gender,phone,identity,appointmentState,turnover)")
    void insert(Agent agent);

    @Update("update agent set license=#{license},identity_card_number=${identityCardNumber}," +
            "register_id=#{registerId},namephotograph=#{namephotograph},gender=${gender}," +
            "phone=#{phone},identity=#{identity},appointment_state=${appointmentState}," +
            "turnover=#{turnover} where id=#{Id}")
    void  updateByPrimaryKey(Agent agent);

    @Delete("delete from agent where id=#{Id}")
    void deleteByPrimaryKey(Integer id);

    @Select("select * from agent where id=#{value}")
    Agent selectById(Integer id);


    @Update("update agent set phone=#{phone} where id=#{id}")
    int updatephoneById(@Param("phone") String phone, @Param("id") Integer id);

    @Update("update agent set name=#{name} where id=#{id}")
    int updateNameById(@Param("name") String name, @Param("id") Integer id);

    @Update("update agent set gender=#{gender} where id=#{id}")
    int updategenderById(@Param("gender") String gender, @Param("id") Integer id);

    @Update("update agent set identity_card_number=#{iden},name=#{name},gender=#{gender} where id=#{id}")
    int updateIdentityById(@Param("iden") String identityCardNumber,@Param("name") String name,@Param("gender") String gender, @Param("id") Integer id);

    @Select("select * from agent where register_id=#{registerId}")
    Agent selectByregisterId(Integer registerId);

    @Insert("insert into agent(register_id,identity) value(#{registerId},'1')")
    void insertById(Integer registerId);

    @Update("update agent set photograph=#{photograph} where id=#{id}")
    int updatephotographById(@Param("photograph") String photograph, @Param("id") Integer agentId);
}